package com.briup.day21;

import java.io.File;

public class Test_File {
    public static void main(String[] args) {
        File f1 = new File("D:\\aaa\\readMe.pdf");
        System.out.println("f1: " + f1);
        System.out.println("文件是否存在: " + f1.exists());
        System.out.println("-------------------------");
        File f2 = new File("D:\\briup");
        System.out.println(f2);
        System.out.println("是否存在: " + f2.exists());
        System.out.println("是否为目录文件：" + f2.isDirectory());
        System.out.println("是否为普通文件：" + f2.isFile());
//        运行效果：
//        注意：length()表示文件长度，如果File对象表示目录，则返回值不确定。
//        2）创建删除操作
        System.out.println("目录长度: " + f2.length());
        System.out.println("------------");
        File f3=new File("aaa.txt");
        System.out.println("f3: " + f3.exists());
        System.out.println("f3路径: " + f3.getPath());
        System.out.println("f3绝对路径: " + f3.getAbsolutePath());
        System.out.println("f3.getName: " + f3.getName());
        System.out.println("f3.length: " + f3.length());
    }
    public static void main01(String[] args) {
        //实例化file对象
        //1.通过字符串路径实例化
        String pathName = "D:\\aaa.txt";
        File file1 = new File(pathName);
        //判断文件是否存在
        System.out.println(file1.exists());
        System.out.println("-----------------------");
        String pathName2 = "D:/aaa/bbb.txt";//朝左的也行
        File file2 = new File(pathName2);
        System.out.println(file2.exists());
        System.out.println("-----------------------");
        String parentDir="D:\\aaa";
        String child= "bbb.txt";
        File file3 = new File(parentDir,child);
        System.out.println("-----------------------");
        File parent=new File("D:\\aaa");
        File file4=new File(parent,"bbb.txt");

        System.out.println(file1);
        System.out.println(file2.toString());
        System.out.println(file3);
        System.out.println(file4);
    }
}
